package com.jishuo.nontax.api.socket.handle;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.ErrorCodeEnum;
import com.jishuo.base.util.SpringContextUtil;
import com.jishuo.nontax.api.socket.ApiHandle;
import com.jishuo.nontax.bean.vo.IllegalactivityinfoVO;
import com.jishuo.nontax.bfc.service.IllegalactivityinfoService;
import org.dom4j.Element;

import java.math.BigDecimal;

/**
 * 交罚接口处理
 *
 * @auther dinggaofei
 * @Date 2023/2/7 16:36
 */
public class IllegalactivityInfoApi implements ApiHandle {
    @Override
    public BaseResult execute(String head, Element body) {
        if (head.equals("getIllegalactivityInfo")) { // 获取交罚票据
            String billnum = body.elementText("billnum");
            if (billnum == null || billnum.length() == 0)
                return new BaseResult(ErrorCodeEnum.PARAM_ERR.getCode(), "参数错误[billnum]");

            IllegalactivityinfoService illegalactivityinfoService = (IllegalactivityinfoService) SpringContextUtil.getBean("illegalactivityinfoService");
            return illegalactivityinfoService.getIllegalactivityInfo(billnum);
        } else if (head.equals("getIllegalactivityInfoOnLine")) { // 获取交罚票据
            String billnum = body.elementText("billnum");
            if (billnum == null || billnum.length() == 0)
                return new BaseResult(ErrorCodeEnum.PARAM_ERR.getCode(), "参数错误[billnum]");

            IllegalactivityinfoService illegalactivityinfoService = (IllegalactivityinfoService) SpringContextUtil.getBean("illegalactivityinfoService");
            BaseResult result = illegalactivityinfoService.getIllegalactivityInfo(billnum);
            //返回数据对象
            if (result.isSuccess()) {
                result.setData(("<retCode>0000</retCode><retMsg>success</retMsg>"+result.getData()));
            }else{
                result.setData(("<retCode>9999</retCode><retMsg>fail</retMsg>"+result.getData()));
            }
            return result;
        } else if (head.equals("setPayInfo")) { //  交罚缴费

            IllegalactivityinfoVO info = new IllegalactivityinfoVO();
            info.setBillnum(body.elementText("billnum"));
            info.setAccountcode(body.elementText("accountcode"));
            info.setIsnohere(Integer.parseInt(body.elementText("isnohere")));
            info.setIsspecialbill(Integer.parseInt(body.elementText("isspecialbill")));
            info.setSpecialbillnum(body.elementText("specialbillnum"));
            info.setPaybankdt(body.elementText("paybankdt"));
            info.setBankstation(body.elementText("bankstation"));
            info.setPaywaycode(body.elementText("paywaycode"));
            info.setBankaffirm(body.elementText("bankaffirm"));
            info.setPaychnl("00");
            info.setPayeraccount("");
            IllegalactivityinfoService illegalactivityinfoService = (IllegalactivityinfoService) SpringContextUtil.getBean("illegalactivityinfoService");
            BaseResult ret = illegalactivityinfoService.setPayInfo(info);
            int n = (ret.isSuccess()) ? 1 : 0;
            ret.setData("<returninfo>" + n + "</returninfo>");
            return ret;
        } else if (head.equals("getIllegalactivityInfoDepositOnLine")) {
            IllegalactivityinfoVO info = new IllegalactivityinfoVO();
            info.setBillnum(body.elementText("billnum"));
            info.setAccountcode("");
            info.setIsnohere(0);
            info.setIsspecialbill(0);
            String bankaffirm = body.elementText("bankaffirm");
            info.setSpecialbillnum(bankaffirm);
            info.setPaybankdt(body.elementText("paybankdt"));
            info.setBankstation("online");
            info.setPaywaycode("03");
            info.setBankaffirm(bankaffirm);
            info.setPaychnl(body.elementText("paychnl"));
            info.setPayeraccount(body.elementText("payeraccount"));
            IllegalactivityinfoService illegalactivityinfoService = (IllegalactivityinfoService) SpringContextUtil.getBean("illegalactivityinfoService");
            BaseResult result = illegalactivityinfoService.setPayInfo(info);
            //返回数据对象
            if (result.isSuccess()) {
                result.setData("<retCode>0000</retCode><retMsg>success</retMsg>");
            }else{
                result.setData("<retCode>9999</retCode><retMsg>fail</retMsg>");
            }
            return result;
        } else if (head.equals("setIllegalactivityCrossPayInfo")) { // 交罚跨省单据

            IllegalactivityinfoVO info = new IllegalactivityinfoVO();
            info.setBillnum(body.elementText("billnum"));
            info.setOccurdatetime(body.elementText("occurdatetime"));
            info.setOpterdatetime(body.elementText("opterdatetime"));
            info.setCertificatenum(body.elementText("certificatenum"));
            info.setOccurname(body.elementText("occurname"));
            info.setPayeeaccountnum(body.elementText("payeeaccountnum"));
            info.setTrafficunitnum(body.elementText("trafficunitnum"));
            info.setFunds(new BigDecimal(body.elementText("funds")));
            info.setLatefee(new BigDecimal(body.elementText("latefee")));
            info.setBankid(Long.parseLong(body.elementText("bankid")));
            info.setPayregion(body.elementText("payregion"));
            info.setBreakaddress(body.elementText("breakaddress"));
            info.setPaychannels(body.elementText("paychannels"));
            info.setRemark(body.elementText("remark"));
            info.setPaybankdt(body.elementText("paybankdt"));
            info.setBankstation(body.elementText("bankstation"));
            info.setBankaffirm(body.elementText("bankaffirm"));
            IllegalactivityinfoService illegalactivityinfoService = (IllegalactivityinfoService) SpringContextUtil.getBean("illegalactivityinfoService");
            BaseResult ret = illegalactivityinfoService.setIllegalactivityCrossPayInfo(info);
            int n = (ret.isSuccess()) ? 1 : 0;
            ret.setData("<returninfo>" + n + "</returninfo>");
            return ret;
        } else if (head.equals("setPunishBillnum")) { //  修改交罚决定书票据号
            String billnum = body.elementText("billnum");
            String specialbillnum = body.elementText("specialbillnum");
            IllegalactivityinfoService illegalactivityinfoService = (IllegalactivityinfoService) SpringContextUtil.getBean("illegalactivityinfoService");
            BaseResult ret = illegalactivityinfoService.setPunishBillnum(billnum, specialbillnum);
            int n = (ret.isSuccess()) ? 1 : 0;
            ret.setData("<returninfo>" + n + "</returninfo>");
            return ret;
        }
        return null;
    }
}
